window.HX_CONFIG = {
    loadingBase: {template: '<ion-spinner icon="android" class="spinner spinner-android" style="stroke: #008fff"><svg style="width: 20px;" viewBox="0 0 64 64"><g transform="rotate(315.7000000000001,32,32)"><circle stroke-width="6" stroke-dasharray="130.10559854346837" stroke-dashoffset="0.33136094674554784" r="26" cx="32" cy="32" fill="none" transform="scale(1,1) translate(0,0) rotate(-270,32,32)"></circle></g></svg></ion-spinner>'},
    loadingTextBase: function (text) {
        return {template: '<ion-spinner icon="android" class="spinner spinner-android" style="stroke: #fff"><svg viewBox="0 0 64 64"><g transform="rotate(315.7000000000001,32,32)"><circle stroke-width="6" stroke-dasharray="130.10559854346837" stroke-dashoffset="0.33136094674554784" r="26" cx="32" cy="32" fill="none" transform="scale(1,1) translate(0,0) rotate(-270,32,32)"></circle></g></svg></ion-spinner><div style="padding-top: 20px;max-width:160px;margin: auto;">' + text + '</div>'}
    },

    // HOST: "http://test.linkcloud.mobi",
    // HOST: location.origin,
    debug: true,

    TEMPLATE_HOST: "asset/car_customer/",
    TEMPLATE_SUFFIX: ".html",
    STATIC_JS_HOST: "asset/car_customer/js/",


    // 判断是否微信
    is_weChat: function () {
        var ua = navigator.userAgent.toLowerCase();
        return ua.match(/MicroMessenger/i) == "micromessenger";
    }
};
// Ionic Starter App
angular.module("myApp", ["ionic", "ngAnimate", "oc.lazyLoad", "myApp.controllers", "myApp.filters", "myApp.directives", "myApp.services"])

    .run(["$ionicPlatform", "$ionicLoading", "$rootScope", "$state", "$location", "$ionicHistory", "$timeout", "toastService",
        function ($ionicPlatform, $ionicLoading, $rootScope, $state, $location, $ionicHistory, $timeout, toastService) {

            $ionicLoading.show(HX_CONFIG.loadingBase);

            HX_CONFIG.width = $(window).width();
            HX_CONFIG.height = $(window).height();

            $rootScope.back = function () {
                $ionicLoading.show(HX_CONFIG.loadingBase);
                history.back();
            };
            $rootScope.stopBubbling = function (e, t) {
                e.stopPropagation();
                t && e.preventDefault();
            };

            $rootScope.rootData = {
                // title: "例子"
            };
            var _title = angular.element('title');
            var _body = angular.element('body');
            $rootScope.$watch("rootData.title", function (n) {
                // _title.html(n || "例子");
                document.title = n || "有车";
                if (HX_CONFIG.is_weChat()) {
                    var _iframe = $("<iframe style='display:none;' src='/favicon.ico'></iframe>");
                    _iframe.on('load', function () {
                        setTimeout(function () {
                            _iframe.off('load').remove();
                        }, 0);
                    }).appendTo(_body);
                }
            });

        }])
    .config(["$stateProvider", "$urlRouterProvider", "$ionicConfigProvider", function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

        $ionicConfigProvider.platform.android.templates.maxPrefetch(5);
        $ionicConfigProvider.platform.ios.templates.maxPrefetch(5);

        $ionicConfigProvider.platform.android.views.maxCache(10);
        $ionicConfigProvider.platform.ios.views.maxCache(10);
        $ionicConfigProvider.views.maxCache(10);

        $ionicConfigProvider.platform.ios.tabs.style('standard');
        $ionicConfigProvider.platform.ios.tabs.position('bottom');
        $ionicConfigProvider.platform.android.tabs.style('standard');
        $ionicConfigProvider.platform.android.tabs.position('bottom');

        $ionicConfigProvider.scrolling.jsScrolling(true);

        $stateProvider

        /**首页**/
            .state('index', {
                url: "/index",
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'mainIndex',
                cache: true
            })
            // 车辆信息
            .state('car', {
                url: '/car',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/car.js').then(function () {
                        });
                    }]
                },
                cache: true
            })

            // 车辆信息首页
            .state('car.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/car/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'carIndex',
                cache: true
            })
            //车辆增加
            .state('car.add', {
              url: '/add/:edit',
              params:{'edit':null},
              templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/car/add_car" + HX_CONFIG.TEMPLATE_SUFFIX,
              controller: 'carAdd',
              cache: true
            })
            // 收藏夹
            .state('collection', {
                url: '/collection',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/collection.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 收藏夹首页
            .state('collection.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/collection/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'collectionIndex',
                cache: true
            })
            // 我的评价
            .state('comment', {
                url: '/comment',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/comment.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 我的评价首页
            .state('comment.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/comment/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'commentIndex',
                cache: true
            })
            // 卡券
            .state('coupon', {
                url: '/coupon',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/coupon.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 卡券首页
            .state('coupon.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/coupon/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'couponIndex',
                cache: true
            })
            // 卡券详情
              .state('coupon.detail', {
                url: '/detail/:id',
                params:{id:null},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/coupon/detail" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'couponDetail',
                cache: true
              })
            // 关注的店铺
            .state('focusStore', {
                url: '/focus_store',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/focus_store.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 关注的店铺首页
            .state('focusStore.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/focus_store/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'focusStoreIndex',
                cache: true
            })
            // 店铺
            .state('shop', {
                url: '/shop',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/shop.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 店铺首页-详情页
            .state('shop.detail', {
                url: '/detail/:id',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/shop/detail" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'shopDetail',
                cache: true
            })
            // 店铺首页-服务详情
            .state('shop.service', {
                url: '/service',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/shop/service" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'shopService',
                cache: true
            })
            // 店铺首页-购买服务
            .state('shop.buy', {
                url: '/buy',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/shop/buy" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'shopBuy',
                cache: true
            })
            // 店铺首页-预约到店
            .state('shop.book', {
                url: '/book',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/shop/book" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'shopBook',
                cache: true
            })
            // 店铺首页-预约成功
            .state('shop.success', {
                url: '/success',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/shop/success" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'shopSuccess',
                cache: true
            })
            // 保险
            .state('insurance', {
                url: '/insurance',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/insurance.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 保险首页
            .state('insurance.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/insurance/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'insuranceIndex',
                cache: true
            })
            // 保险详情
              .state('insurance.detail', {
                url: '/detail/:id',
                params: {id:null},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/insurance/detail" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'insuranceDetail',
                cache: true
              })
              // 保险详情
              .state('insurance.call', {
                url: '/call/:id',
                params: {id:null},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/insurance/call" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'insuranceCall',
                cache: true
              })
            // 驾照
            .state('license', {
                url: '/license',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/license.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 驾照首页
            .state('license.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/license/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'licenseIndex',
                cache: true
            })
            // 驾照首页
              .state('license.add', {
                url: '/add',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/license/add" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'licenseAdd',
                cache: true
              })
            // 订单
            .state('order', {
                url: '/order',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/order.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 订单首页
            .state('order.index', {
                url: '/index/:type',
                params: {type:0},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/order/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'orderIndex',
                cache: true
            })
            // 订单详情
              .state('order.detail', {
                url: '/detail/:id',
                params: {id:null},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/order/detail" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'orderDetail',
                cache: true
              })
            //订单评价
              .state('order.comment', {
                url: '/comment/:id',
                params: {id:null},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/order/comment" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'orderComment',
                cache: true
              })
              //订单评价成功
              .state('order.success', {
                url: '/comment/success/:id',
                params: {id:null},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/order/success" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'orderSuccess',
                cache: true
              })
            // 合作商个人中心
            .state('partner', {
                url: '/partner',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/partner.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 合作商个人中心首页
            .state('partner.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'partnerIndex',
                cache: true
            })
            // 合作商-附近
            .state('nearby', {
                url: '/partner/nearby',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/nearby.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 合作商-附近停车场
            .state('nearby.park', {
                url: '/car_park',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/nearby/car_park" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'nearbyPark',
                cache: false
            })
            // 合作商-附近加油站
            .state('nearby.filling', {
                url: '/car_filling',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/nearby/car_filling" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'nearbyFilling',
                cache: false
            })
            // 合作商-附近保养
            .state('nearby.upkeep', {
                url: '/car_upkeep',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/nearby/car_upkeep" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'nearbyUpkeep',
                cache: false
            })
            // 合作商-附近维修
            .state('nearby.maintain', {
                url: '/car_maintain',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/nearby/car_maintain" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'nearbyMaintain',
                cache: false
            })
            // 合作商-附近洗车
            .state('nearby.wash', {
                url: '/car_wash',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/nearby/car_wash" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'nearbyWash',
                cache: false
            })
            // 合作商-搜索
            .state('search', {
                url: '/partner/search',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/search.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 合作商-搜索
            .state('search.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/search/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'searchIndex',
                cache: true
            })
            // 合作商-附近搜索
            .state('search.nearby', {
                url: '/near_search',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/partner/search/near_search" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'searchNearby',
                cache: true
            })
            // 个人中心
            .state('personal', {
                url: '/personal',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/personal.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 个人中心首页
            .state('personal.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/personal/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'personalIndex',
                cache: true
            })
            // 我的预约
            .state('reservation', {
                url: '/reservation',
                template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
                resolve: {
                    ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/reservation.js').then(function () {
                        });
                    }]
                },
                cache: true
            })
            // 我的预约首页
            .state('reservation.index', {
                url: '/index',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/reservation/index" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'reservationIndex',
                cache: true
            })
            // 我的预约首页
              .state('reservation.detail', {
                url: '/detail',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/reservation/detail" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'reservationDetail',
                cache: true
              })
            //个人信息
            .state('info', {
              url: '/info',
              template: '<ion-nav-view class="slide-left-right"></ion-nav-view>',
              resolve: {
                ollc: ['$ocLazyLoad', function ($ocLazyLoad) {
                  return $ocLazyLoad.load(HX_CONFIG.STATIC_JS_HOST + 'controllers/info.js').then(function () {
                  });
                }]
              },
              cache: true
            })
            //我的预约首页
            .state('info.index', {
              url: '/index',
              templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/info/index" + HX_CONFIG.TEMPLATE_SUFFIX,
              controller: 'infoIndex',
              cache: true
            })
            //我的预约首页
              .state('info.detail', {
                url: '/detail/:edit',
                params:{edit:null},
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/info/detail" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'infoDetail',
                cache: true
              })
              //我的预约首页
              .state('info.avatar', {
                url: '/avatar',
                templateUrl: HX_CONFIG.TEMPLATE_HOST + "tpl/info/avatar" + HX_CONFIG.TEMPLATE_SUFFIX,
                controller: 'infoAvatar',
                cache: true
              })

        $urlRouterProvider.otherwise('/index');
    }]);


